package com.example.Nurse_Notifier;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HistArrayAdapter extends ArrayAdapter<HistString> {

    Context context;
    HistContainer histContainer;
    Typeface typefaceRegular;
    Typeface typefaceBold;

    static class ViewHolder {
        TextView deviceId;
        TextView time;
        ImageView tvWeatherImage;
    }

    public HistArrayAdapter(Activity context, HistContainer histContainer) {
        super(context, R.layout.hist_row, histContainer);
        this.histContainer = histContainer;
        this.context = context;
        typefaceRegular = Typeface.createFromAsset(context.getAssets(), "Roboto-Regular.ttf");
        typefaceBold = Typeface.createFromAsset(context.getAssets(), "Roboto-Bold.ttf");
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getView(position, convertView);
    }

    public View getView(int position, View convertView) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = convertView;
        ViewHolder holder;

        if (convertView == null) {
            v = inflater.inflate(R.layout.hist_row, null);
            holder = new ViewHolder();
            holder.deviceId = (TextView) v.findViewById(R.id.histDevicePrimary);
            holder.deviceId.setTypeface(typefaceBold);
            holder.time = (TextView) v.findViewById(R.id.histDeviceSecondary);
            holder.time.setTypeface(typefaceRegular);
            holder.tvWeatherImage = (ImageView) v.findViewById(R.id.image);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        holder.tvWeatherImage.setImageDrawable(histContainer.get(position).getDrawable());
        holder.deviceId.setText((position + 1) + ". " + histContainer.get(position).getPrimaryString());
        holder.time.setText(histContainer.get(position).getSecondaryString());
        return v;
    }
}
